﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Text;
using System.Net;
using System.Collections;
using System.Web.Security;
using System.Runtime.InteropServices;

namespace iResume
{
    public partial class contactUS : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            name.Text = "";
            subject.Text = "";
            email.Text = "";
            content.Text = "";
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //Session["email"] = email.Text;
            //string emailt = (string)(Session["Email"]);
            //create the message
            MailMessage mail = new MailMessage();
            //add the email address we will be sending the message to
            mail.To.Add("iResumee@gmail.com");
            //add our email here
            mail.From = new MailAddress(email.Text);
            //email's subject
            mail.Subject = subject.Text;
            //email's body, this is going to be html. note that we attach the image as using cid
            mail.Body = "<br>" + "<b>Sender email address:</b>" + " " + email.Text + "<br>" + "<br>" + "The content is:" + " " + content.Text;
            //set email's body to html
            mail.IsBodyHtml = true;

            //add our attachment
            //Attachment imgAtt = new Attachment(Server.MapPath("re.gif"));
            //give it a content id that corresponds to the src we added in the body img tag
            //imgAtt.ContentId = "re.gif";
            //add the attachment to the email
            //mail.Attachments.Add(imgAtt);

            //setup our smtp client, these are Gmail specific settings
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.EnableSsl = true; //ssl must be enabled for Gmail
            //our Gmail account credentials
           NetworkCredential credentials = new NetworkCredential("iResumee@gmail.com", "yiweileeling");
           // NetworkCredential credentials = new NetworkCredential(email.Text, "");
            //add credentials to our smtp client
          client.Credentials = credentials;

            try
            {
                //try to send the mail message
                client.Send(mail);
                name.Text = "";
                subject.Text = "";
                email.Text = "";
                content.Text = "";
            }
            catch
            {
                //some feedback if it does not work
           
            }
            
        }
    }
}